home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / Mystery Science Mac / App Sources / Speech.h < prev   
Text File  |  1993-04-22  |  10KB  |  275 lines

  1. /*
  2.     File:        Speech.h
  3.  
  4.     Contains:    Interfaces to Speech Manager
  5.  
  6.     Written by:    Tim Schaaff
  7.  
  8.     Copyright:    © 1991-1992 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <5>    11/30/92    TIM        Renamed callback function typedefs to fix name-space conflicts
  13.                                     between Speech Mgr and Quicktime Movies.h and to make them more
  14.                                     Speech Mgr specific.
  15.          <4>    10/28/92    TIM        Put badPhonemeText error code back into API.
  16.          <3>     9/15/92    TIM        Removed badStructLen, unimplMsg, badSelector, badParmVal error
  17.                                     return. Added “voiceNotFound” error return. Added length param
  18.                                     to GetVoiceDescription. Prefixed some constants with “k” to
  19.                                     conform to Apple naming conventions.
  20.          <2>     7/23/92    TIM        Switch resource and file type defines over to the “official”
  21.                                     ones from Brian McGhie.
  22.          <1>     7/6/92        TIM        Add support for Voice management routines
  23.          <0>     6/24/92    TIM        Bring interfaces up to date with 1.0a7 spec
  24.         <-1>     4/21/92    TIM        Bring interfaces up to date with 1.0a5 spec
  25.         <-2>     2/13/92    TIM        Bring interfaces up to date with 1.0a3 spec
  26.         <-3>    11/19/91    TIM        Pass voice Handle argument to ReadNthVoice and ReadNamedVoice by
  27.                                     reference
  28.         <-4>    11/14/91    TIM        Flesh out more of the API
  29.         <-5>    11/11/91    TIM        Bring interfaces up to date with ERS
  30.         <-6>     11/6/91    TIM        first checked in
  31.  
  32. */
  33.  
  34. #ifndef _Speech_
  35. #define _Speech_
  36.  
  37. #ifndef __TYPES__
  38. #include <Types.h>
  39. #endif
  40.  
  41. #ifndef __MEMORY__
  42. #include <Memory.h>
  43. #endif
  44.  
  45. #ifndef __FILES__
  46. #include <Files.h>
  47. #endif
  48.  
  49.  
  50. #define gestaltSpeechAttr             'ttsc'    /* Gestalt Manager selector for Speech Attributes */
  51.     
  52. enum {
  53.     gestaltSpeechMgrPresent = 0                /* Gestalt bit which indicates that Speech Manager exists */
  54. };
  55.  
  56. #define kTextToSpeechSynthType         'ttsc'    /* Text-to-Speech Synthesizer component type     */
  57. #define kTextToSpeechVoiceType         'ttvd'    /* Text-to-Speech Voice resource type             */
  58. #define kTextToSpeechVoiceFileType     'ttvf'    /* Text-to-Speech Voice file type                 */
  59. #define kTextToSpeechVoiceBundleType 'ttvb'    /* Text-to-Speech Voice Bundle file type        */
  60.  
  61. enum {                                        /* Speech Manager error codes (Range from 240 - 259) */
  62.     noSynthFound         = -240,
  63.     synthOpenFailed     = -241,
  64.     synthNotReady        = -242,
  65.     bufTooSmall         = -243,
  66.     voiceNotFound        = -244,
  67.     incompatibleVoice    = -245,
  68.     badDictFormat         = -246,
  69.     badPhonemeText        = -247
  70. };
  71.         
  72. enum {                                        /* constants for SpeakBuffer and TextDone callback controlFlags bits */
  73.     kNoEndingProsody     = 1,
  74.     kNoSpeechInterrupt     = 2,
  75.     kPreflightThenPause    = 4
  76. };
  77.  
  78. enum {                                        /* constants for StopSpeechAt and PauseSpeechAt */
  79.     kImmediate        = 0,
  80.     kEndOfWord        = 1,
  81.     kEndOfSentence    = 2
  82. };
  83.  
  84. #define soStatus                'stat'        /* GetSpeechInfo & SetSpeechInfo selectors */
  85. #define soErrors                'erro'
  86. #define soInputMode                'inpt'
  87. #define soCharacterMode            'char'
  88. #define soNumberMode            'nmbr'
  89. #define soRate                    'rate'
  90. #define soPitchBase                'pbas'
  91. #define soPitchMod                'pmod'
  92. #define soVolume                'volm'
  93. #define soSynthType                'vers'
  94. #define soRecentSync            'sync'
  95. #define soPhonemeSymbols        'phsy'
  96. #define soCurrentVoice            'cvox'
  97. #define soCommandDelimiter        'dlim'
  98. #define soReset                    'rset'
  99. #define soCurrentA5                'myA5'
  100. #define soRefCon                'refc'
  101. #define soTextDoneCallBack        'tdcb'
  102. #define soSpeechDoneCallBack    'sdcb'
  103. #define soSyncCallBack            'sycb'
  104. #define soErrorCallBack            'ercb'
  105. #define soPhonemeCallBack        'phcb'
  106. #define soWordCallBack            'wdcb'
  107. #define soSynthExtension        'xtnd'
  108.  
  109. /* Speaking Mode Constants */
  110.  
  111. #define modeText        'TEXT'        /* input mode constants                 */
  112. #define modeTX            'TX'
  113. #define modePhonemes    'PHON'
  114. #define modePH            'PH'
  115. #define modeNormal        'NORM'        /* character mode and number mode constants */
  116. #define modeLiteral        'LTRL'
  117.  
  118. enum {                                /* GetVoiceInfo selectors                 */
  119.     soVoiceDescription    = 'info',    /* gets basic voice info                 */
  120.     soVoiceFile            = 'fref'    /* gets voice file ref info             */
  121. };
  122.  
  123. typedef struct SpeechChannelRecord {
  124.     long data[1];
  125. } SpeechChannelRecord;
  126.  
  127. typedef SpeechChannelRecord *SpeechChannel;
  128.  
  129. typedef struct VoiceSpec {
  130.     OSType    creator;                /* creator id of required synthesizer     */
  131.     OSType    id;                        /* voice id on the specified synth         */
  132. } VoiceSpec;
  133.  
  134. enum {kNeuter = 0, kMale, kFemale};    /* returned in gender field below         */
  135.  
  136. typedef struct VoiceDescription {
  137.     long        length;                /* size of structure - set by application     */
  138.     VoiceSpec     voice;                /* voice creator and id info                 */
  139.     long        version;            /* version code for voice                     */
  140.     Str63        name;                /* name of voice                             */
  141.     Str255        comment;            /* additional text info about voice         */
  142.     short        gender;                /* neuter, male, or female                    */
  143.     short        age;                /* approximate age in years                 */
  144.     short        script;                /* script code of text voice can process     */
  145.     short        language;            /* language code of voice output speech     */
  146.     short         region;                /* region code of voice output speech         */
  147.     long        reserved[4];        /* always zero - reserved for future use    */
  148. } VoiceDescription;
  149.  
  150. typedef struct VoiceFileInfo {
  151.     FSSpec        fileSpec;            /* volume, dir, & name information for voice file */
  152.     short        resID;                /* resource id of voice in the file */
  153. } VoiceFileInfo;
  154.  
  155. typedef struct SpeechStatusInfo {
  156.     Boolean    outputBusy;             /* TRUE if audio is playing         */
  157.     Boolean    outputPaused;            /* TRUE if channel is paused         */
  158.     long    inputBytesLeft;         /* bytes left to process             */
  159.     short    phonemeCode;            /* opcode for cur phoneme             */
  160. } SpeechStatusInfo;
  161.  
  162. typedef struct SpeechErrorInfo {
  163.     short    count;                    /* # of errs since last check         */
  164.     OSErr    oldest;                    /* oldest unread error                 */
  165.     long    oldPos;                    /* char position of oldest err         */
  166.     OSErr    newest;                    /* most recent error                 */
  167.     long    newPos;                    /* char position of newest err         */
  168. } SpeechErrorInfo;
  169.  
  170. typedef struct SpeechVersionInfo {
  171.     OSType        synthType;            /* always ‘ttsc’                     */
  172.     OSType        synthSubType;        /* synth flavor                     */
  173.     OSType        synthManufacturer;    /* synth creator ID                 */
  174.     long        synthFlags;            /* synth feature flags                 */
  175.     NumVersion    synthVersion;         /* synth version number             */
  176. } SpeechVersionInfo;
  177.  
  178. typedef struct PhonemeInfo {
  179.     short    opcode;                    /* opcode for the phoneme             */
  180.     Str15    phStr;                    /* corresponding char string         */
  181.     Str31    exampleStr;                /* word that shows use of phoneme     */
  182.     short    hiliteStart;            /* segment of example word that         */
  183.     short    hiliteEnd;                /* should be hilighted (ala TextEdit) */
  184. } PhonemeInfo;
  185.  
  186. typedef struct PhonemeDescriptor {
  187.     short        phonemeCount;         /* # of elements         */
  188.     PhonemeInfo    thePhonemes[1];     /* element list         */
  189. } PhonemeDescriptor;
  190.  
  191. typedef struct SpeechXtndData {
  192.     OSType    synthCreator;            /* synth creator id     */
  193.     Byte    synthData[2];            /* data TBD by synth     */
  194. } SpeechXtndData;
  195.  
  196. typedef struct DelimiterInfo {
  197.     Byte    startDelimiter[2];        /* defaults to “[[“     */
  198.     Byte    endDelimiter[2];        /* defaults to “]]“     */
  199. } DelimiterInfo;
  200.  
  201. typedef pascal void (*SpeechTextDoneCBPtr)     (SpeechChannel, long, Ptr *, long *, long *);    /* Text-done callback routine typedef     */
  202. typedef pascal void (*SpeechDoneCBPtr)         (SpeechChannel, long );                            /* Speech-done callback routine typedef */
  203. typedef pascal void (*SpeechSyncCBPtr)         (SpeechChannel, long, OSType);                    /* Sync callback routine typedef         */
  204. typedef pascal void (*SpeechErrorCBPtr)     (SpeechChannel, long, OSErr, long);                /* Error callback routine typedef         */
  205. typedef pascal void (*SpeechPhonemeCBPtr)     (SpeechChannel, long, short);                    /* Phoneme callback routine typedef     */
  206. typedef pascal void (*SpeechWordCBPtr)         (SpeechChannel, long, long, short);                /* Word callback routine typedef         */
  207.  
  208. #ifdef __cplusplus
  209. extern "C" {
  210. #endif
  211.  
  212. pascal NumVersion SpeechManagerVersion (void)
  213.     = {0x203C,0x0000,0x000C,0xA800};
  214.  
  215. pascal OSErr MakeVoiceSpec (OSType creator, OSType id, VoiceSpec *voice)
  216.     = {0x203C,0x0604,0x000C,0xA800};
  217. pascal OSErr CountVoices (short *numVoices)
  218.     = {0x203C,0x0108,0x000C,0xA800};
  219. pascal OSErr GetIndVoice (short index, VoiceSpec *voice)
  220.     = {0x203C,0x030C,0x000C,0xA800};
  221. pascal OSErr GetVoiceDescription (VoiceSpec *voice, VoiceDescription *info, long infoLength)
  222.     = {0x203C,0x0610,0x000C,0xA800};
  223. pascal OSErr GetVoiceInfo (VoiceSpec *voice, OSType selector, void *voiceInfo)
  224.     = {0x203C,0x0614,0x000C,0xA800};
  225.  
  226. pascal OSErr NewSpeechChannel (VoiceSpec *voice, SpeechChannel *chan)
  227.     = {0x203C,0x0418,0x000C,0xA800};
  228. pascal OSErr DisposeSpeechChannel (SpeechChannel chan)
  229.     = {0x203C,0x021C,0x000C,0xA800};
  230.  
  231. pascal OSErr SpeakString (StringPtr s)
  232.     = {0x203C,0x0220,0x000C,0xA800};
  233. pascal OSErr SpeakText (SpeechChannel chan, Ptr textBuf, long textBytes)
  234.     = {0x203C,0x0624,0x000C,0xA800};
  235. pascal OSErr SpeakBuffer (SpeechChannel chan, Ptr textBuf, long textBytes, long controlFlags)
  236.     = {0x203C,0x0828,0x000C,0xA800};
  237.  
  238. pascal OSErr StopSpeech (SpeechChannel chan)
  239.     = {0x203C,0x022C,0x000C,0xA800};
  240. pascal OSErr StopSpeechAt (SpeechChannel chan, long whereToStop)
  241.     = {0x203C,0x0430,0x000C,0xA800};
  242. pascal OSErr PauseSpeechAt (SpeechChannel chan, long whereToPause)
  243.     = {0x203C,0x0434,0x000C,0xA800};
  244. pascal OSErr ContinueSpeech (SpeechChannel chan)
  245.     = {0x203C,0x0238,0x000C,0xA800};
  246.  
  247. pascal short SpeechBusy (void)
  248.     = {0x203C,0x003C,0x000C,0xA800};
  249. pascal short SpeechBusySystemWide (void)
  250.     = {0x203C,0x0040,0x000C,0xA800};
  251.     
  252. pascal OSErr SetSpeechRate (SpeechChannel chan, Fixed rate)
  253.     = {0x203C,0x0444,0x000C,0xA800};
  254. pascal OSErr GetSpeechRate (SpeechChannel chan, Fixed *rate)
  255.     = {0x203C,0x0448,0x000C,0xA800};
  256. pascal OSErr SetSpeechPitch (SpeechChannel chan, Fixed pitch)
  257.     = {0x203C,0x044C,0x000C,0xA800};
  258. pascal OSErr GetSpeechPitch (SpeechChannel chan, Fixed *pitch)
  259.     = {0x203C,0x0450,0x000C,0xA800};
  260. pascal OSErr SetSpeechInfo (SpeechChannel chan, OSType selector, void *speechInfo)
  261.     = {0x203C,0x0654,0x000C,0xA800};
  262. pascal OSErr GetSpeechInfo (SpeechChannel chan, OSType selector, void *speechInfo)
  263.     = {0x203C,0x0658,0x000C,0xA800};
  264.  
  265. pascal OSErr TextToPhonemes (SpeechChannel chan, Ptr textBuf, long textBytes, Handle phonemeBuf, long *phonemeBytes) 
  266.     = {0x203C,0x0A5C,0x000C,0xA800};
  267.  
  268. pascal OSErr UseDictionary (SpeechChannel chan, Handle dictionary)
  269.     = {0x203C,0x0460,0x000C,0xA800};
  270.     
  271. #ifdef __cplusplus
  272. }
  273. #endif
  274. #endif
  275.